package com.example.p002_juc;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class CountDownLatch_Test {

    @Test
    public void test() {

        CountDownLatch latch = new CountDownLatch(2);

        for (int i = 0; i < 2; i++) {
            new Thread(() ->{

                ThreadUtil.sleep(RandomUtil.randomInt(3), TimeUnit.SECONDS);

                latch.countDown();

            }).start();
        }


        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
